/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file taskdescriptor.h
 * @author Davide Giuseppe Monaco
 *
 * This header file contains TaskDescriptor class declaration.
 */

#ifndef _TASKDESCRIPTOR_H_
#define _TASKDESCRIPTOR_H_ 1

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <string>

/**
 * Enumeration that specifies the type of task allowed in the distributed system.
 */
enum TaskTYPE
{
	Executable, scriptBash
};

/**
 * @brief TaskDescriptor class represents a single tasks that some UI submits
 * to the distributed system.
 */
class TaskDescriptor
{
	private:

    // enables boost serialization access
    friend class boost::serialization::access;

    /**
     * @brief Serialization member function.
     *
     * boost::serialization needs it.
     */
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version)
    {
      ar & _ID;
      ar & _type;
      ar & _command;
      ar & _link;
    }

    /**
     * @brief Current TaskDescriptor ID.
     */
		int _ID;

    /**
     * @brief Task type according to TaskTYPE enumeration.
     */
		TaskTYPE _type;

    /**
     * @brief String containing the command to be executed in order to
     *        run the task.
     *
     * This is needed by the Worker.
     */
    std::string _command;

    /**
     * @brief String containing the location of the executable file to run
     *        for the current task.
     */
    std::string _link;

	public:
    /**
     * @brief Default Constructor.
     */
		TaskDescriptor(void);

    /**
     * @brief Constructor specifying current TaskDescriptor ID.
     * @param id  current TaskDescriptor ID.
     */
		TaskDescriptor(int id);

     /**
     * @brief Constructor specifying current TaskDescriptor, TaskTYPE , Command and Link
     * @param ID   current TaskDescriptor ID 
     * @param type TaskDescriptor's type, according to TaskTYPE enumeration.
     * @param cmd  TaskDescriptor's command to execute.
     * @param link TaskDescriptor's link to the executable in the system.
     */
     TaskDescriptor(int ID, TaskTYPE type, const std::string& cmd, const std::string& link);

    /**
     * @brief Destructor.
     */
		~TaskDescriptor();

    /**
     * @brief Returns current TaskDescriptor id.
     * @return current TaskDescriptor id.
     */
		int getID(void) const;

    /**
     * @brief Set current TaskDescriptor id.
     * @param val   current TaskDescriptor id.
     */
		void setID(int val);

    /**
     * @brief Returns current TaskDescriptor type according to TaskTYPE enum.
     * @return current TaskDescriptor type.
     */
		TaskTYPE getType(void) const;

    /**
     * @brief Set current TaskDescriptor type to the provided one,
     *        according to TaskTYPE enum.
     * @param val   the provided TaskTYPE.
     */
		void setType(TaskTYPE val);

    /**
     * @brief Returns current TaskDescriptor command string.
     * @return current TaskDescriptor command.
     */
    const std::string& getCommand(void) const;

    /**
     * @brief Set current TaskDescriptor command string to the provided one.
     * @param val   the provided string.
     */
		void setCommand(const std::string& val);

    /**
     * @brief Returns current TaskDescriptor link string.
     * @return current TaskDescriptor link.
     */
    const std::string& getLink(void) const;

    /**
     * @brief Set current TaskDescriptor link string to the provided one.
     * @param val   the provided string.
     */
    void setLink(const std::string& val);

    friend std::ostream& operator << (std::ostream& os, const TaskDescriptor& ts);
};

#endif /* _TASKDESCRIPTOR_H_ */
